package com.tgy.algorithm._经典题目01;

/**
 * 在行也有序、列也有序的二维数组中，找num，找到返回true，否则false
 */
public class _008_行有序列有序的二维数组中查找数 {

    public static boolean findNum(int[][] nums,int k) {

        int row = nums.length;
        int col = nums[0].length;

        int i = 0;
        int j = col - 1;

        while (i < row && j >= 0) {
            if (nums[i][j] == k) {
                return true;
            }else if(nums[i][j] < k) {
                i++;
            }else {
                j--;
            }
        }

        return false;
    }

    public static void main(String[] args) {

        int[][] nums = {
                {1,2,3,4,5},
                {6,7,8,9,10},
                {11,12,13,14,15},
                {16,17,18,19,20},
        };
        boolean num = findNum(nums, 13);
        System.out.println(num);
    }
}
